const app = getApp();
var util = require('../../utils/util.js');
var picRoot = app.data.picRoot;
var url = app.data.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    envPic: [
      'http://www.runoob.com/try/demo_source/paris.jpg', 'http://www.runoob.com/try/demo_source/paris.jpg'
    ],
    beginDayStyle: [
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' },
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5' }
    ],
    outDayStyle: [
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#84e7d0' },
      { month: 'current', day: new Date().getDate(), color: 'white', background: '#84e7d0' }
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 500,
    activeNames: ['1'],
    addr: '广东省云浮市新兴县祥顺大酒店',
    businessTime: '营业时间:每天8点 ~ 每天17点',
    serviceContent: 'aaasssss',
    lat: '',
    lot: '',
    merchantId: 40,
    phone: '0766-2899668',
    arr: [],
    name: '',
    detailShow: false,
    roomDetailShow: false,
    inRoomDateShow: false,
    outRoomDateShow: false,
    beginDateStr: '',
    endDateStr: '',
    mainFileList: [],
    mainImg: false,
    overLayShow: false
  },
  toShowHotel: function(option){
    let _that = this;
    let merchantId = _that.data.merchantId;
    wx.navigateTo({
      url: '/pages/show-hotel/index?merchantId=' + merchantId
    })
  },
  /**弹框 */
  onOverLayShow() {
    this.setData({ overLayShow: true });
  },
  onOverLayHide() {
    this.setData({ overLayShow: false });
  },
  toMainImg: function(){
    let _that = this;
    _that.setData({
      mainImg: true
    })
  },
  onMainImgClose: function(){
    let _that = this;
    _that.setData({
      mainImg: false
    })
  },
  afterRead(event) {
    const { file } = event.detail;
    console.log(file);
    let _that = this;
    // _that.onOverLayShow();
    for(var i = 0; i<file.length; i++){
      wx.uploadFile({
        url: url + '/HotelSystemApi/uploadPic',
        filePath: file[i].path,
        header: {
          "Content-Type": "multipart/form-data"
        },
        name: 'file',
        success(res) {
          // 上传完成需要更新 fileList
          const { mainFileList = [] } = _that.data;
          mainFileList.push({ ...file, url: picRoot + res.data });
          _that.setData({ mainFileList });
        }
      });
    }
  },
  emptyBeginTime: function (options) {
    let _that = this;
    _that.setData({
      beginDateStr: ''
    })
  },
  emptyEndTime: function (options) {
    let _that = this;
    _that.setData({
      endDateStr: ''
    })
  },
  confirmBeginDate: function () {
    let _that = this;
    let str = _that.data.beginDateStr;
    if (!str) {
      wx.showToast({
        title: "请选择入住时间",
        icon: "none",
        duration: 2000
      })
      return;
    }
    _that.setData({
      inRoomDateShow: false
    });
  },
  confirmEndDate: function () {
    let _that = this;
    let str = _that.data.endDateStr;
    if (!str) {
      wx.showToast({
        title: "请选择离开时间",
        icon: "none",
        duration: 2000
      })
      return;
    }
    _that.setData({
      outRoomDateShow: false
    });
  },
  inDayClick: function (event) {
    let clickDay = event.detail.day;
    let changeDay = `beginDayStyle[1].day`;
    let changeBg = `beginDayStyle[1].background`;
    let year = event.detail.year;
    let month = event.detail.month;
    month = month < 10 ? ('0' + month) : month;
    let day = event.detail.day;
    day = day < 10 ? ('0' + day) : day;
    let str = year + "-" + month + "-" + day;
    this.setData({
      [changeDay]: clickDay,
      [changeBg]: "#FFdd55",
      beginDateStr: str
    })
  },
  outDayClick: function (event) {
    let clickDay = event.detail.day;
    let changeDay = `outDayStyle[1].day`;
    let changeBg = `outDayStyle[1].background`;
    let year = event.detail.year;
    let month = event.detail.month;
    month = month < 10 ? ('0' + month) : month;
    let day = event.detail.day;
    day = day < 10 ? ('0' + day) : day;
    let str = year + "-" + month + "-" + day;
    this.setData({
      [changeDay]: clickDay,
      [changeBg]: "#FFdd55",
      endDateStr: str
    })
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let merchantId = options.merchantId;
    let _that = this;
    // _that.setData({
    //   merchantId: merchantId
    // })
    wx.setNavigationBarTitle({
      title: "酒店管理"
    })
    
    
  },

  /**
   * 打开入住时间日历
   */
  openBeginDate: function(options) {
    let _that = this;
    _that.setData({
      inRoomDateShow: true
    });
  },
  closeBeginDate: function() {
    let _that = this;
    _that.setData({
      inRoomDateShow: false
    });
  },

  /**
   * 打开离开时间日历
   */
  openOutDate: function(options) {
    let _that = this;
    _that.setData({
      outRoomDateShow: true
    });
  },
  closeOutDate: function() {
    let _that = this;
    _that.setData({
      outRoomDateShow: false
    });
  },

  /**
   * 打开房间详情
   */
  openRoomDetail: function(options) {
    let _that = this;
    _that.setData({
      roomDetailShow: true
    });
  },
  closeRoomDetail: function() {
    let _that = this;
    _that.setData({
      roomDetailShow: false
    });
  },
  /**
   * 预定
   */
  preBug: function(options) {
    console.log("预定");
  },
  /***
   * 打开酒店详情
   */
  toHotelDetail: function(oiptions) {
    let _that = this;
    _that.setData({
      detailShow: true
    });
  },
  onClose() {
    let _that = this;
    _that.setData({
      detailShow: false
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})